<% layout("/inc/layout_page.html"){ %>

<form action="${BASE}/admin/AdminRole/save" id="form_save" method="post">
<input type="hidden" id="id" name="id" value="${obj.id}">
<input type="hidden" id="sid" name="sid" value="${obj.sid}">
<input id="menuSids" name="menuSids" type="hidden">
<div class="box">
  <div class="box-header">
    <h4 class="box-title"><i class="fa fa-bars"></i> 修改系统角色</h4>
    <div class="box-tools">
      <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-save"></i> 保存</button>
      <a href="javascript:;" onclick="layer_close()" class="btn btn-info btn-sm"><i class="fa fa-chevron-left"></i> 返回</a>
    </div>
  </div>
  <div class="box-body">
    <table class="table tform table-bordered">
      <tr>
        <th width="20%"><label for="name">角色名称：</label></th>
        <td width="30%"><input id="name" name="name" value="${obj.name}" type="text" class="form-control"></td>
        <th width="20%"><label for="enname">英文名称：</label></th>
        <td width="30%"><input id="enname" name="enname" value="${obj.enname}" type="text" class="form-control"></td>
      </tr>
      <tr>
        <th><label for="summary">角色描述：</label></th>
        <td colspan="3"><input id="summary" name="summary" value="${obj.summary}" type="text" class="form-control"></td>
      </tr>
      <tr>
        <th><label>可操作菜单：</label></th>
        <td colspan="3"><ul id="menuTreeList" class="ztree"></ul></td>
      </tr>
    </table>
  </div>
  <div class="box-footer">
    <div class="box-tools pull-right">
      <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-save"></i> 保存</button>
      <a href="javascript:;" onclick="layer_close()" class="btn btn-info btn-sm"><i class="fa fa-chevron-left"></i> 返回</a>
    </div>
  </div>
</div>
</form>

<script type="text/javascript">
var tree_setting = {
		check:{
			enable: true,
			chkboxType:{ "Y" : "ps", "N" : "ps" }
		}
	};
$(function(){
	$.getJSON("${BASE}/admin/AdminMenu/menuTreeDataWithChecked",{roleSid:"${obj.sid}"},function(jsondata){
		var treeObj = $.fn.zTree.init($("#menuTreeList"), tree_setting, jsondata);
		treeObj.expandAll(true);
	});
	
	$("#form_save").validate({
		errorPlacement: function(error, element) {
			error.appendTo(element.parent());
		},
		submitHandler : function(form) {
			layer.load(1, {shade: [0.3,'#fff']});

			var zTree = $.fn.zTree.getZTreeObj("menuTreeList");
			var nodes = zTree.getCheckedNodes(true);
			var menuids = "";
			for(var i in nodes){
				menuids += ","+nodes[i].sid;
			}
			$("#menuSids").val(menuids);
			
			$(form).ajaxSubmit({
				dataType:"json",
				success:function( jsondata ){
					layer.closeAll('loading');
					if( jsondata.success){
						parent.toastr.success('保存成功！');
						parent.reload_table();
						layer_close();
					}else{
						toastr.error(jsondata.msg);
					}
				}
			});
		},
		rules : {
			name : {
				required : true
			}
		}, 
		messages : { 
			name : { 
				required : "名称不能为空"
			}
		}
	});
});
</script>
<% } %>